Fix DPO IPO log-prob normalization - #9925
Open
taking-lying-flat wants to merge 1 commit into
Open
Conversation
taking-lying-flat
marked this pull request as ready for review
August 16, 2026 21:56
taking-lying-flat
force-pushed
the
agent/fix-dpo-ipo-normalization
branch
from
September 5, 2026 00:13
490e336 to
a745abe
Compare
taking-lying-flat
force-pushed
the
agent/fix-dpo-ipo-normalization
branch
from
September 6, 2026 10:28
a745abe to
127a141
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR type
PR information
IPO currently divides the shared per-token log-probabilities by
loss_mask.sum(-1)before reducing them into sequences. This can fail broadcasting for padded batches, uses the entire packed row as the denominator for padding-free/packed batches, and also normalizes the sigmoid component when sigmoid and IPO are combined.Keep forward outputs and cached reference log-probabilities as sequence sums. Count valid completion tokens per sequence using the existing vectorized packed reduction, then normalize both policy and reference scores only for the IPO component. Clamp counts to at least one for empty completions.
Preserve
logps/chosenandlogps/rejectedas sums and reportlogps_mean/chosenandlogps_mean/rejectedfor IPO. These metrics use the existing trainer logging path; with--report_to wandb, the W&B callback logstrain/logps_mean/{chosen,rejected}andeval/logps_mean/{chosen,rejected}.Only
swift/rlhf_trainers/dpo_trainer.pychanges: 29 insertions and 9 deletions.Experiment results
CPU validation with PyTorch 2.13.0, Transformers 5.14.1 and TRL 1.9.2:
store_metrics -> Trainer.log -> WandbCallbackpath with a captured W&B API call. No live W&B run was created.mainreproduce the padded broadcasting error and incorrect standalone/mixed IPO loss values; standalone sigmoid matches the independent formula.uvx pre-commit run --all-filesandgit diff --checkpassed.Validation used tiny CPU logits; a full multi-GPU training run was not performed.